- main_toolbar do |t|
  - exports = []
  - exports << :sales_invoice if resource.invoice?
  - exports << :sales_order if resource.order?
  - exports << :sales_estimate if resource.estimate? || resource.draft? || resource.refused?
  = t.export(*exports, key: :number)
  = t.duplicate resource, method: :post, params: {redirect: nil}
  - if current_user.can?(:write, :outgoing_deliveries) && resource.can_generate_parcel?
    = t.new(resource, params: { controller: :parcels, sale_id: resource.id, nature: :outgoing }, label: :generate_parcel.tl)
  - if resource.invoice?
    = t.cancel(resource) if resource.cancellable?
  = t.edit resource if resource.draft?
  = t.destroy if resource.destroyable?

= main_state_bar(resource)

= main_informations attachment: true do
  = attributes_list do |l|
    - l.attribute :client, :label => :label, url: true
    - l.attribute :number
    - l.attribute :initial_number if resource.invoice?
    - l.attribute :state_label
    - l.attribute :responsible, :label => :full_name
    - l.attribute :confirmed_at if resource.confirmed_at?
    - l.attribute :invoiced_at if resource.invoiced_at?
    - l.attribute :credited_sale, url: true if resource.invoice? and resource.credited_sale
    - l.attribute :payment_delay, :label => :name
    - l.attribute :nature
    - l.attribute :currency unless resource.currency == Preference[:currency]
    - l.attribute :description if resource.description?
    - l.attribute :address, :label => :coordinate
    -# l.attribute :delivery_address, :label => :coordinate
    - l.attribute :invoice_address, :label => :coordinate
    - l.attribute(:journal_entry, url: true) if resource.journal_entry
    - l.attribute :undelivered_invoice_journal_entry, url: true if resource.undelivered_invoice_journal_entry
    - l.attribute :quantity_gap_on_invoice_journal_entry, url: true if resource.quantity_gap_on_invoice_journal_entry
    - l.attribute(:affair, label: :number, url: true) if resource.affair
    - l.attribute :letter_format
    - if resource.letter_format?
      - l.attribute :subject
      - l.attribute :function_title
      - l.attribute :introduction
      - l.attribute :conclusion

= cobbles do |c|
  - c.cobble :items, title: Sale.human_attribute_name(:items) do
    = cobble_list :items do
      %tr.total
        %th{colspan: 5}= :total.tl
        %td= resource.pretax_amount.l(currency: resource.currency)
        %td= resource.amount.l(currency: resource.currency)

  - if resource.subscriptions.any?
    - c.cobble :subscriptions, title: :x_subscriptions.tl(count: resource.subscriptions.count) do
      = cobble_list :subscriptions

  - c.cobble(:affair, title: Sale.human_attribute_name(:affair)) do
    = affair_of(resource, default: 'IncomingPayment')

  - if resource.parcels.any?
    - c.cobble :parcels, title: Sale.human_attribute_name(:parcels) do
      = cobble_list :parcels

  - if resource.credits.any?
    - c.cobble :credits do
      = cobble_list :credits
